﻿@model List<WebEntities.Models.Framework.Member>

@{
    ViewBag.Title = "网站管理平台_用户管理视图";
}

@section HeadContent
{
    <script type="text/javascript">
        var renderMemStatus = function (value) {
            var result = "";
            switch (value) {
                case 1:
                    result = "活动";
                    break;
                case 2:
                    result = "冻结";
                    break;
                default:
                    break;
            }
            return result;
        };

        var renderMemType = function (value) {
            var result = "";
            switch (value) {
                case 1:
                    result = "网站会员";
                    break;
                case 2:
                    result = "协会会员";
                    break;
                case 3:
                    result = "网站管理员";
                    break;
                default:
                    break;
            }
            return result;
        };

        var renderEmailValid = function (value) {
            var result = "";
            if (value == 1) {
                result = "已验证";
            }
            else {
                result = "未验证";
            }
            return result;
        };

//        var gridCmd = function (sender, cmd, record) {
//            console.log(sender);
//            switch (cmd) {
//                case "edit":
//                    break;
//                case "delete":
//                    Ext.Msg.confirm('提示', '是否要删除该用户？', function (answer) {
//                        if (answer == "yes") {
//                            var grid = sender.up("grid");
//                            grid.store.remove(record);

//                        }
//                    });
//                    break;
//                default:
//                    break;
//            }
//        };

//        var onDelSucess = function (result) {
//            var optr = result.OptrSuccess;
//            switch (optr) {
//                case "edit":
//                    break;
//                case "delete":
//                    App.GridPanel1.store.reload();
//                    break;
//                default:
//                    break;
//            }
//        };
    </script>
}

@(Html.X().Menu()
    .ID("Grid1CtxMenu")
    .Items(
        Html.X().MenuItem().Text("编辑用户").Icon(Icon.BookEdit)
            .DirectEvents(de =>
            {
                de.Click.Action = "EditMemberWindow";
                de.Click.ExtraParams.Add(new Parameter("gid", "this.parentMenu.dataRecord.data.GID", ParameterMode.Raw));
            }),
            Html.X().MenuItem().Text("删除用户").Icon(Icon.Cross).Listeners(ls => ls.Click.Handler = "App.BtnDeleteSel.getEl().dom.click()")
    )
)

@Html.X().Hidden().ID("DeleteHint").Text("是否要删除选中的用户？")

@(Html.X().Viewport()
        .Layout("fit")
        .Items(
            Html.X().GridPanel()
                .ID("GridPanel1")
                .Title("用户管理视图")
                .Store(
                    Html.X().StoreForModel()
                        .AutoSync(true)
                        .ShowWarningOnFailure(false)
                        .PageSize(50)
        //.AutoLoadParams(ap => {
        //    ap.Add(Html.X().Parameter()
        //        .Name("start")
        //        .Value("0")
        //        .Mode(ParameterMode.Raw)
        //    );
        //    ap.Add(Html.X().Parameter()
        //        .Name("limit")
        //        .Value("50")
        //        .Mode(ParameterMode.Raw)
        //    );
        //})
                        .Proxy(proxy => proxy.Add(Html.X().AjaxProxy()
                            .Url(Url.Action("GetAllMembers"))
                            .ExtraParams(ep =>
                            {
                                Parameter p1 = new Parameter
                                {
                                    Name = "memType",
                                    Value = "3",
                                    Mode = ParameterMode.Raw
                                };
                                ep.Add(p1);
                            })
                            .Reader(Html.X().JsonReader().Root("data"))
                            .Writer(writer => new JsonWriter { AllowSingle = true, Root = "data" })
                            .API(api => { api.Destroy = Url.Action("DeleteMember"); })
                        ))
                        .Listeners(ls => ls.Write.Fn = "ext.net.comjs.onGridChange")
                )
                .ColumnModel(
                    Html.X().RowNumbererColumn(),
                    Html.X().Column().DataIndex(Model, m => m.MemberID).Text("用户ID"),
                    Html.X().Column().DataIndex(Model, m => m.NickName).Text("用户昵称"),
                    Html.X().DateColumn().DataIndex(Model, m => m.CreateTime).Width(120).Text("创建时间").Format("yyyy-MM-dd HH:mm:ss"),
                    Html.X().Column().DataIndex(Model, m => m.Email).Text("电子邮件"),
                    Html.X().Column().DataIndex(Model, m => m.EmailValid).Text("邮箱地址验证").Renderer("renderEmailValid"),
                    Html.X().DateColumn().DataIndex(Model, m => m.LastLoginTime).Width(120).Text("最后登录时间").Format("yyyy-MM-dd HH:mm:ss"),
                    Html.X().Column().DataIndex(Model, m => m.LoginCount).Text("登录次数"),
                    Html.X().Column().DataIndex(Model, m => m.MemStatus).Text("用户状态").Renderer("renderMemStatus"),
                    Html.X().Column().DataIndex(Model, m => m.MemType).Text("用户类型").Renderer("renderMemType")
        //.DirectEvents(de =>
        //    {
        //        de.Command.Action = "HandlerChanges";
        //        de.Command.EventMask.ShowMask = true;
        //        de.Command.Confirmation.ConfirmRequest = true;
        //        de.Command.Confirmation.Title = "提示";
        //        de.Command.Confirmation.Message = "是否要删除该用户？";
        //        de.Command.ExtraParams.Add(new Parameter { Name = "cmd", Value = "command", Mode = ParameterMode.Raw });
        //        de.Command.ExtraParams.Add(new Parameter { Name = "memId", Value = "record.data.MemberID", Mode = ParameterMode.Raw });
        //        de.Command.Success = "onDelSucess(result.result)";
        //    })
        //.Listeners(ln => ln.Command.Fn = "gridCmd")
                 )
                .SelectionModel(Html.X().CheckboxSelectionModel().Mode(SelectionMode.Multi))
                .Listeners(ls =>
                {
                    ls.ItemContextMenu.Handler = "e.preventDefault(); App.Grid1CtxMenu.dataRecord = this.store.getAt(index); App.Grid1CtxMenu.showAt(e.getXY());";
                })
                .View(Html.X().GridView().StripeRows(true))
                .DirectEvents(de =>
                {
                    de.ItemDblClick.Action = "EditMemberWindow";
                    de.ItemDblClick.ExtraParams.Add(new Parameter("gid", "record.data['GID']", ParameterMode.Raw));
                })
                .TopBar(
                    Html.X().Toolbar()
                        .Items(
                            Html.X().Button().Text("新建用户").Icon(Icon.Add).DirectClickAction("NewMemberWindow"),
                            Html.X().Button().ID("BtnDeleteSel").Text("删除用户").Icon(Icon.Cross)
                                .Listeners(
                                    ls => ls.Click.Fn = "ext.net.comjs.deleteGridSelected"
                                )
                        )
                )
                .BottomBar(
                    Html.X().PagingToolbar()
                        .Items(
                            Html.X().Label("每页显示行数："),
                            Html.X().ToolbarSpacer(10),
                            Html.X().ComboBox()
                                .Width(80)
                                .Items("10", "50", "100")
                                .SelectedItems("50")
                                .Listeners(lr =>
                                {
                                    lr.Select.Fn = "ext.net.comjs.onPageSizeChange";
                                })
                        )
                )
        )
)